<template>
  <div class="modal-form-container">
    <vuescroll :ops="ops">
      <Form class="mr10 ml10" ref="info" :model="data" :label-width="100">
        <FormItem :label="$t('ukexJfHe1YBGx8B9XnGdu')">
          <Input v-model="data.equipmentid" :disabled="true" />
        </FormItem>
        <FormItem :label="$t('OBojq5D694WY1CWDUxEBu')">
          <Input v-model="data.number" />
        </FormItem>
        <FormItem :label="$t('_yoJoamsOOOKfJ6q0O9bt')">
          <Select v-model="data.yktype" @on-change="changeType">
            <Option value="0">{{$t('PURyezKy-Uv9IGFuF7gtn')}}</Option>
            <Option value="1">{{$t('c1pzunMuu2JTAdGdOflpc')}}</Option>
            <Option value="2">{{$t('CkrEAPIpqJl5SnvZqes4s')}}</Option>
            <Option value="3">{{$t('2fdneRvddGVhMKigENgzY')}}</Option>
            <Option value="4">{{$t('2yA6X74h518F_0iL71h6h')}}</Option>
          </Select>
        </FormItem>
        <FormItem v-if="data.yktype == 0" :label="$t('DyFHLriFxsvqhbeY8xUPW') + '(' + $t('rEwoS7D6EkR6EPGHSq6MU') + ')'">
          <Input v-model="data.ykvalue"/>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="save">{{$t('leMLybFumlrF7lrDkz19u')}}</Button>
          <Button style="margin-left: 8px" @click="close">{{$t('2LFpg56tAgKyBB40xpv5l')}}</Button>
        </FormItem>
      </Form>
    </vuescroll>
  </div>
</template>

<script>
import vuescroll from 'vuescroll'
import { createEquipmentCommandYK, createEquipmentCommandYKResetBill } from '@/api/data2'

export default {
  name: 'control_form_info',
  components: {
    vuescroll
  },
  props: {
    data: Object,
    status: String
  },
  data () {
    return {
      ops: {
        scrollPanel: {
          maxHeight: 500
        }
      }
    }
  },
  methods: {
    changeType () {

    },
    close () {
      this.$emit('close')
    },
    transform () {
      return Object.assign({}, this.data, {
        number: +this.data.number,
        yktype: +this.data.yktype,
        ykvalue: +this.data.ykvalue
      })
    },
    async save () {
      const data = this.transform()
      const { code, desc } =
        data.yktype == 2
          ? await createEquipmentCommandYKResetBill({ ...data })
          : await createEquipmentCommandYK({ ...data })
      if (code == 200) {
        // this.$emit('success', desc)
        this.$Message.success(desc || this.$t('4dfj0GS91RclHHT8Bw-ir'))
      } else {
        // this.$emit('fail', desc)
        this.$Message.error(desc)
      }
    }
  }
}
</script>
